package com.ny.zmb.openapi.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ny.zmb.openapi.ysutil.from.BizReqJsonCollege.*;
import com.ny.zmb.openapi.ysutil.utils.RequestNoUntil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigInteger;

import static com.ny.zmb.openapi.constant.PHPConstant.JAVA_BASE_URL;

@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("pm_register")
public class PmRegister implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 用户ID
     */
    private Integer userId;
    /**
     * 外部商户号，由平台商提供，每次请求保证唯一
     */
    private String outMerchantNo;
    /**
     * 商户号 由YS提供，每次请求保证唯一
     */
    private String merchantNo;
    /**
     * 商户类型：类型不同，需上传的图片不同
     * 01-个体商户，按营业执照上类型选择
     * 02-企业商户，按营业执照上类型选择
     * 03-小微商户，无营业执照；
     * 04-合作伙伴,hh
     * 注：小微商户无法使用POS终端交易
     */
    private String merchantType;
    /**
     * 商户名称
     * 商户类型为小微，参考 【小微商户命名规范】
     * 商户类型为个体、企业时传营业执照上全称
     * 若个体户营业执照上名称为空或*时，商户名称为“个体户+法人姓名”，示例：个体户张三
     */
    private String merchantName;
    /**
     * 商户简称 ，用于显示收款方名称
     */
    private String merchantShortName;
    /**
     * 营业执照号
     * 商户类型为个体、企业时必填
     */
    private String businessCode;
    /**
     * 营业执照全称
     * 商户类型为个体、企业时必填
     */
    private String businessName;
    /**
     * 营业执照起始日期，格式：yyyyMMdd
     * 商户类型为个体、企业时必填
     * 注：按营业执照上面的成立时间为准
     */
    private String businessExpire;
    /**
     * 营业执照失效日期，格式：yyyyMMdd，长期填29991231
     * 商户类型为个体、企业时必填
     */
    private String businessFailure;
    /**
     * 营业执照注册地址
     * 商户类型为个体、企业时必填
     */
    private String businessAddress;
    /**
     * 经营地址
     * 注：地址需要与所在市一致否则会进件失败
     */
    private String bizAddress;
    /**
     * 经营所在省（传中文，取值参考：调用公共接口-地区码查询接口），如：广东省
     */
    private String province;
    /**
     * 经营所在市（传中文，取值参考：调用公共接口-地区码查询接口），如：深圳市
     */
    private String city;
    /**
     * 经营所在区（传中文，取值参考：调用公共接口-地区码查询接口），如：龙华区 注：如市不存在区时，无需传值
     */
    private String region;
    /**
     * 法人姓名
     */
    private String lawyerName;
    /**
     * 法人手机号
     * 注：个体、小微类型请与结算账户的借记卡开卡预留手机号码一致，否则会四要素校验失败
     */
    private String lawyerPhone;
    /**
     * 法人证件号
     */
    private String lawyerId;
    /**
     * 法人证件起始日期 格式：yyyyMMdd
     */
    private String lawyerIdExpired;
    /**
     * 法人证件失效日期，格式：yyyyMMdd
     * 长期填29991231
     */
    private String lawyerIdFailure;
    /**
     * 法人国籍（传编号）
     * 商户类型为个体、企业时必填
     * 249-中国
     */
    private String lawyerCountry;
    /**
     * 法人职业（传编号）
     * 商户类型为个体、企业时必填
     * 1-机关团体企事业单位 2-公共事业
     * 3-农牧业 4-交通运输业 5-餐旅业
     * 6-建筑工程业 7-制造业 8-医疗保健业
     * 9-娱乐业 10-其他
     */
    private String lawyerWork;
    /**
     * 法人性别：01-男 02-女
     * 商户类型为个体、企业时必填
     */
    private String lawyerSex;
    /**
     * 法人地址
     * 商户类型为个体、企业时必填
     */
    private String lawyerAddress;
    /**
     * 法人证件类型
     * 00-身份证
     * 01-中国护照
     * 02-军人身份证
     * 03-警官证
     * 04-户口簿
     * 05-临时身份证
     * 06-外国护照
     * 07-港澳通行证
     * 08-台胞通行证
     * 18-其他证件
     * 19-营业执照
     */
    private String lawyerIdType;
    /**
     * 结算账户卡类型
     * 11-对私借记卡
     * 21-对公借记卡
     * 注：企业商户仅支持对公借记卡
     */
    private String accountCardType;
    /**
     * 结算账户卡号
     */
    private String accountCardno;
    /**
     * 结算账户户名
     */
    private String accountCardnoName;
    /**
     * 开户行省（传中文，取值参考：调用公共接口-地区码查询接口），如：广东省
     */
    private String openAccProvince;
    /**
     * 开户行市（传中文，取值参考：调用公共接口-地区码查询接口），如：深圳市
     */
    private String openAccCity;
    /**
     * 开户行区（传中文，取值参考：调用公共接口-地区码查询接口），如：龙华区
     * 注：如市不存在区时，无需传值
     */
    private String openAccArea;
    /**
     * 开户行编号（传联名行号，取值参考：调用公共接口-开户行查询接口）
     */
    private String openAccBanktype;
    /**
     * 联系人姓名（业务经办人姓名）
     */
    private String personName;
    /**
     * 联系人证件号（业务经办人证件号）
     */
    private String personId;
    /**
     * 联系人手机号（业务经办联系手机号）
     */
    private String personPhone;
    /**
     * 联系人邮箱（业务经办联系邮箱）
     */
    private String personEmail;
    /**
     * 联系人地址
     */
    private String personAddress;
    /**
     * MCC码（取值参考：调用公共接口-mcc码查询接口）
     */
    private String mccCode;
    /**
     * 结算起始金额，单位：元
     * 必须为正整数，最小值为0元
     * 默认为10元，不修改无需传值
     * 待结算金额(不包含未分账金额)＜结算起始金额时不会自动结算
     */
    private String lowestStlAmt;
    /**
     * 结算方式，不传值默认01
     * 01-银行账户(自动结算到银行账户)
     * 02-平台内账户(自动结算到一般消费账户，需调用接口提现到银行账户)
     */
    private String settleType;
    /**
     * 报备类型，不传值默认01
     * 01-自动报备（同时报备微信和支付宝）
     * 02-手动报备（需要时再调用商户报备接口）
     * 03-自动报备（仅报备微信）
     * 04-自动报备（仅报备支付宝）
     * 注：无需微信或支付宝收款时请选择手动报备，自动报备需开通对应权限。
     */
    private String reportType;
    /**
     * 进件结果通知，不传值默认01
     * 01-不通知(默认值)
     * 02-联系人邮件通知
     * 03-联系人短信通知
     * 04-联系人邮箱+短信通知
     */
    private String notifyType;
    /**
     * 进件结果异步回调URL，为空则不发送
     */
    private String notifyAddress;
    /**
     * 下列为资质图片字段，传值为文件上传接口返回的fileCode
     */
    /**
     * 营业执照图片编号
     * 商户类型为个体、企业时必填
     * 文件上传接口返回的fileCode
     */
    private String businessPic;
    /**
     * 结算账户卡正面（有卡号面）图片编号
     * 企业商户为开户许可证或企业开户的纸质证明文件
     * 文件上传接口返回的fileCode
     */
    private String accountCardPicFront;
    /**
     * 法人证件正面图片（人像）编号
     * 文件上传接口返回的fileCode
     */
    private String lawyerIdPicFront;
    /**
     * 法人证件反面图片（国徽）编号
     * 文件上传接口返回的fileCode
     */
    private String lawyerIdPicBack;
    /**
     * 法人手持证件正面图片编号
     * 文件上传接口返回的fileCode
     */
    private String lawyerIdHandFront;
    /**
     * 门头照图片编号
     * 文件上传接口返回的fileCode
     */
    private String doorFrontPic;
    /**
     * 收银台照图片编号
     * 文件上传接口返回的fileCode
     */
    private String cashierPic;
    /**
     * 场景照图片编号
     * 文件上传接口返回的fileCode
     */
    private String scenePic;

    public PmRegister(String outMerchantNo) {
        this.outMerchantNo = outMerchantNo;
        this.setSettleType("01");
        this.setReportType("01");
        this.setReportType("01");
        this.setNotifyAddress(JAVA_BASE_URL + "/notify/registerNotify");
    }

    public PmRegister(Integer userId) {
        this.userId = userId;
        this.outMerchantNo = RequestNoUntil.generateNumericTaskNumber();
        this.setSettleType("01");
        this.setReportType("01");
        this.setReportType("01");
        this.setNotifyAddress(JAVA_BASE_URL + "/notify/registerNotify");
    }

    public PmRegister(Integer userId, String outMerchantNo) {
        this.userId = userId;
        this.outMerchantNo = outMerchantNo;
        this.setSettleType("01");
        this.setReportType("01");
        this.setReportType("01");
        this.setNotifyAddress(JAVA_BASE_URL + "/notify/registerNotify");
    }

    public PmRegister(String outMerchantNo, Integer userId) {
        this.userId = userId;
        this.outMerchantNo = outMerchantNo;
        this.setSettleType("01");
        this.setReportType("01");
        this.setReportType("01");
        this.setNotifyAddress(JAVA_BASE_URL + "/notify/registerNotify");
    }

    public void setNullToEmpty() {
        if (businessPic == null) {
            this.businessPic = "";
        }
        if (accountCardPicFront == null) {
            this.accountCardPicFront = "";
        }
        if (lawyerIdPicFront == null) {
            this.lawyerIdPicFront = "";
        }
        if (lawyerIdPicBack == null) {
            this.lawyerIdPicBack = "";
        }
        if (lawyerIdHandFront == null) {
            this.lawyerIdHandFront = "";
        }
        if (doorFrontPic == null) {
            this.doorFrontPic = "";
        }
        if (cashierPic == null) {
            this.cashierPic = "";
        }
        if (scenePic == null) {
            this.scenePic = "";
        }
    }

    public void update(BizReqJsonRegister obj) {
        this.outMerchantNo = obj.getOutMerchantNo() == null || obj.getOutMerchantNo().isEmpty() ? null : obj.getOutMerchantNo();
        this.merchantType = obj.getMerchantType() == null || obj.getMerchantType().isEmpty() ? null : obj.getMerchantType();
        this.merchantName = obj.getMerchantName() == null || obj.getMerchantName().isEmpty() ? null : obj.getMerchantName();
        this.merchantShortName = obj.getMerchantShortName() == null || obj.getMerchantShortName().isEmpty() ? null : obj.getMerchantShortName();
        this.businessCode = obj.getBusinessCode() == null || obj.getBusinessCode().isEmpty() ? null : obj.getBusinessCode();
        this.businessName = obj.getBusinessName() == null || obj.getBusinessName().isEmpty() ? null : obj.getBusinessName();
        this.businessExpire = obj.getBusinessExpire() == null || obj.getBusinessExpire().isEmpty() ? null : obj.getBusinessExpire();
        this.businessFailure = obj.getBusinessFailure() == null || obj.getBusinessFailure().isEmpty() ? null : obj.getBusinessFailure();
        this.businessAddress = obj.getBusinessAddress() == null || obj.getBusinessAddress().isEmpty() ? null : obj.getBusinessAddress();
        this.bizAddress = obj.getBizAddress() == null || obj.getBizAddress().isEmpty() ? null : obj.getBizAddress();
        this.province = obj.getProvince() == null || obj.getProvince().isEmpty() ? null : obj.getProvince();
        this.city = obj.getCity() == null || obj.getCity().isEmpty() ? null : obj.getCity();
        this.region = obj.getRegion() == null || obj.getRegion().isEmpty() ? null : obj.getRegion();
        this.lawyerName = obj.getLawyerName() == null || obj.getLawyerName().isEmpty() ? null : obj.getLawyerName();
        this.lawyerPhone = obj.getLawyerPhone() == null || obj.getLawyerPhone().isEmpty() ? null : obj.getLawyerPhone();
        this.lawyerId = obj.getLawyerId() == null || obj.getLawyerId().isEmpty() ? null : obj.getLawyerId();
        this.lawyerIdExpired = obj.getLawyerIdExpired() == null || obj.getLawyerIdExpired().isEmpty() ? null : obj.getLawyerIdExpired();
        this.lawyerIdFailure = obj.getLawyerIdFailure() == null || obj.getLawyerIdFailure().isEmpty() ? null : obj.getLawyerIdFailure();
        this.lawyerCountry = obj.getLawyerCountry() == null || obj.getLawyerCountry().isEmpty() ? null : obj.getLawyerCountry();
        this.lawyerWork = obj.getLawyerWork() == null || obj.getLawyerWork().isEmpty() ? null : obj.getLawyerWork();
        this.lawyerSex = obj.getLawyerSex() == null || obj.getLawyerSex().isEmpty() ? null : obj.getLawyerSex();
        this.lawyerAddress = obj.getLawyerAddress() == null || obj.getLawyerAddress().isEmpty() ? null : obj.getLawyerAddress();
        this.lawyerIdType = obj.getLawyerIdType() == null || obj.getLawyerIdType().isEmpty() ? null : obj.getLawyerIdType();
        this.accountCardType = obj.getAccountCardType() == null || obj.getAccountCardType().isEmpty() ? null : obj.getAccountCardType();
        this.accountCardno = obj.getAccountCardno() == null || obj.getAccountCardno().isEmpty() ? null : obj.getAccountCardno();
        this.accountCardnoName = obj.getAccountCardnoName() == null || obj.getAccountCardnoName().isEmpty() ? null : obj.getAccountCardnoName();
        this.openAccProvince = obj.getOpenAccProvince() == null || obj.getOpenAccProvince().isEmpty() ? null : obj.getOpenAccProvince();
        this.openAccCity = obj.getOpenAccCity() == null || obj.getOpenAccCity().isEmpty() ? null : obj.getOpenAccCity();
        this.openAccArea = obj.getOpenAccArea() == null || obj.getOpenAccArea().isEmpty() ? null : obj.getOpenAccArea();
        this.openAccBanktype = obj.getOpenAccBanktype() == null || obj.getOpenAccBanktype().isEmpty() ? null : obj.getOpenAccBanktype();
        this.personName = obj.getPersonName() == null || obj.getPersonName().isEmpty() ? null : obj.getPersonName();
        this.personId = obj.getPersonId() == null || obj.getPersonId().isEmpty() ? null : obj.getPersonId();
        this.personPhone = obj.getPersonPhone() == null || obj.getPersonPhone().isEmpty() ? null : obj.getPersonPhone();
        this.personEmail = obj.getPersonEmail() == null || obj.getPersonEmail().isEmpty() ? null : obj.getPersonEmail();
        this.personAddress = obj.getPersonAddress() == null || obj.getPersonAddress().isEmpty() ? null : obj.getPersonAddress();
        this.mccCode = obj.getMccCode() == null || obj.getMccCode().isEmpty() ? null : obj.getMccCode();
        this.lowestStlAmt = obj.getLowestStlAmt() == null || obj.getLowestStlAmt().isEmpty() ? null : obj.getLowestStlAmt();
        this.settleType = obj.getSettleType() == null || obj.getSettleType().isEmpty() ? null : obj.getSettleType();
        this.reportType = obj.getReportType() == null || obj.getReportType().isEmpty() ? null : obj.getReportType();
        this.notifyType = obj.getNotifyType() == null || obj.getNotifyType().isEmpty() ? null : obj.getNotifyType();
        this.notifyAddress = obj.getNotifyAddress() == null || obj.getNotifyAddress().isEmpty() ? null : obj.getNotifyAddress();
        this.businessPic = obj.getBusinessPic() == null || obj.getBusinessPic().isEmpty() ? null : obj.getBusinessPic();
        this.accountCardPicFront = obj.getAccountCardPicFront() == null || obj.getAccountCardPicFront().isEmpty() ? null : obj.getAccountCardPicFront();
        this.lawyerIdPicFront = obj.getLawyerIdPicFront() == null || obj.getLawyerIdPicFront().isEmpty() ? null : obj.getLawyerIdPicFront();
        this.lawyerIdPicBack = obj.getLawyerIdPicBack() == null || obj.getLawyerIdPicBack().isEmpty() ? null : obj.getLawyerIdPicBack();
        this.lawyerIdHandFront = obj.getLawyerIdHandFront() == null || obj.getLawyerIdHandFront().isEmpty() ? null : obj.getLawyerIdHandFront();
        this.doorFrontPic = obj.getDoorFrontPic() == null || obj.getDoorFrontPic().isEmpty() ? null : obj.getDoorFrontPic();
        this.cashierPic = obj.getCashierPic() == null || obj.getCashierPic().isEmpty() ? null : obj.getCashierPic();
        this.scenePic = obj.getScenePic() == null || obj.getScenePic().isEmpty() ? null : obj.getScenePic();
    }
}
